package servlet;

import biz.ProductBiz;
import entity.Products;
import utils.PagesUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2016/4/19 0019.
 */
@WebServlet(name = "PagesServlet", urlPatterns = "/pages.do")
public class PagesServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取每页分为多少条
        int pageCount = Integer.parseInt(request.getParameter("pageCount"));
        // 获得第几页
        int pageNum = Integer.parseInt(request.getParameter("pageNum"));

        ProductBiz productBiz = new ProductBiz();
        // 调用biz方法获得数据
        PagesUtils<Products> pros = productBiz.getPageDatas(pageNum, pageCount);
        // 将数据存放到request空间
        request.setAttribute("pages", pros);
        // 请求转发到request空间，为了使request不变
        request.getRequestDispatcher("product.jsp").forward(request,response);
    }
}
